package com.oocl.crm.service.impl;

import com.oocl.crm.base.DNode;
import com.oocl.crm.command.Command;
import com.oocl.crm.command.impl.LookUpCommand;
import com.oocl.crm.db.UserLinkedList;
import com.oocl.crm.exception.ParameterErrorException;
import com.oocl.crm.pojo.User;
import com.oocl.crm.service.BusinessService;

/**
 * 查询业务处理
 * 
 * @author GANAB
 * 
 */
public class LookUpBusinessService extends BusinessService {

	public String service(Command command) throws ParameterErrorException {
		LookUpCommand lookupCommand = (LookUpCommand) command;

		// 正则已经能排除格式问题，直接取数据
		String[] fields = lookupCommand.getQueryField();
		if (fields != null && fields.length > 0) {
			// 查询结果
			UserLinkedList queryResult = this.getUserDB().get(fields);
			if (queryResult != null) {
				String resultStr = "";
				DNode<User> temp = queryResult.getFirst();
				int i = 0;
				while (temp != null) {
					resultStr += "User data:[" + (++i) + "]" + temp.data.toString() + "\n";
					temp = temp.next;
				}
				return resultStr;
			}
		}
		return null;
	}

}
